﻿#region 命名空间

using System.Text.RegularExpressions;

#endregion

namespace Sharp.Infrastructure
{
    /// <summary>
    ///     正则表达式
    /// </summary>
    public class RegexHepler
    {
        /// <summary>
        ///     匹配图片
        /// </summary>
        public static readonly Regex Images = new Regex("<img[^>]*src=(\"|')(?<src>[^(\"|')]*)(\"|')[^>]*>",
            RegexOptions.IgnoreCase | RegexOptions.Compiled);

        /// <summary>
        ///     匹配简体中文
        /// </summary>
        public static readonly Regex Chinese = new Regex("([\u4e00-\u9fa5])+",
            RegexOptions.Compiled);

        /// <summary>
        ///     电邮
        /// </summary>
        public static readonly Regex EMail =
            new Regex(
                @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$",
                RegexOptions.IgnoreCase | RegexOptions.Compiled);

        /// <summary>
        ///     日期
        /// </summary>
        public static readonly Regex Date =
            new Regex(
                @"^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$",
                RegexOptions.Compiled);

        /// <summary>
        ///     html和脚本
        /// </summary>
        public static readonly Regex HtmlScript = new Regex("<[^>]*>",
            RegexOptions.Compiled);

        /// <summary>
        ///     空行
        /// </summary>
        public static readonly Regex Invisible = new Regex(@"([\r\n])[\s]+", RegexOptions.Compiled);

        /// <summary>
        ///     HTML 注释
        /// </summary>
        public static readonly Regex HtmlNote = new Regex(@"<!--[\S\s]+?-->", RegexOptions.Compiled);

        /// <summary>
        ///     脚本
        /// </summary>
        public static readonly Regex Javascript = new Regex("<script[^>]*?>.*?</script>",
            RegexOptions.IgnoreCase | RegexOptions.Compiled);

        /// <summary>
        ///     样式表
        /// </summary>
        public static readonly Regex Style = new Regex("<Style[^>]*?>.*?</Style>",
            RegexOptions.IgnoreCase | RegexOptions.Compiled);
    }
}